package architecture.admin.user.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import architecture.admin.user.entity.AdmUser;
import architecture.admin.user.service.AdmUserService;
import architecture.base.action.BaseAction;

public class LoginAction extends BaseAction{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	private AdmUserService admUserService;
	
	private AdmUser admUser = new AdmUser();

	private String name;
	private String password;
	
	private List<AdmUser> userList;
	
	public String execute(){
		// TODO Auto-generated method stub
		
		return SUCCESS;
	}

	public String verify(){
		Map<String, Object> sessionMap = new HashMap<String, Object>();
		sessionMap.put("ip",super.httpServletRequest.getRemoteAddr());
		sessionMap.put("username", name);
		sessionMap.put("password", password);
		super.setSession(sessionMap);
		return SUCCESS;
	}
	
	@Override
	public String list() {
		// TODO Auto-generated method stub
		userList = admUserService.findAll();
		System.out.println("has "+userList.size()+" records");
		return SUCCESS;
	}

	public String toAddPage(){
		return SUCCESS;
	}
	@Override
	public String create() {
		// TODO Auto-generated method stub
		admUser.setRegistered(new Date());
		admUser.setStutas(0);
		admUser.setDeleteflag(0);
		admUserService.save(admUser);
		admUserService.flush();
		return SUCCESS;
	}

	@Override
	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String delete() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
	/**
	 * @return the admUser
	 */
	public AdmUser getAdmUser() {
		return admUser;
	}

	/**
	 * @param admUser the admUser to set
	 */
	public void setAdmUser(AdmUser admUser) {
		this.admUser = admUser;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the userList
	 */
	public List<AdmUser> getUserList() {
		return userList;
	}

	/**
	 * @param userList the userList to set
	 */
	public void setUserList(List<AdmUser> userList) {
		this.userList = userList;
	}
	
}
